package com.ruoyi.laiqianba.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 账户类型枚举
 * */
@Getter
public enum AccountTypeEnum {

    MERCHANT("MERCHANT", "商户")
    ,PRODUCT("PRODUCT", "产品")
//    ,CHANNEL("CHANNEL", "渠道")
    ,ACCOUNT("ACCOUNT", "总账户")
    ;

    private String value;
    private String name;

    AccountTypeEnum(String value, String name){
        this.value = value;
        this.name = name;
    }

    public static List<Map<String, String>> getAccountTypeMapList(){
        List<Map<String, String>> resultList = new ArrayList<>();
        for (AccountTypeEnum accountTypeEnum : values()) {
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("key", accountTypeEnum.getName());
            itemMap.put("value", String.valueOf(accountTypeEnum.getValue()));
            resultList.add(itemMap);
        }
        return resultList;
    }

    public static AccountTypeEnum getEntityByType(String actionType){
        for (AccountTypeEnum typeEnum : values()) {
            if (StrUtil.equals(typeEnum.getValue(), actionType)){
                return typeEnum;
            }
        }
        return null;
    }

    //通过value拿到name值
    public static String getNameByValue(String value){
        for (AccountTypeEnum typeEnum : values()) {
            if (StrUtil.equals(typeEnum.getValue(), value)){
                return typeEnum.getName();
            }
        }
        return null;
    }

}
